class Solution(object):
    def hasAllCodes(self, s, k):
        n = len(s)
        if n - k + 1 < 2 ** k:
            return False
        p = [0] * 2 ** k
        for i in range(n - k + 1):
            p[int((s[i: i + k]), 2)] = 1
        return all(p)
